package com.mtons.mblog.modules.repository;

import com.mtons.mblog.modules.entity.Favorite;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

/**
 * 数据层
 * @author langhsu
 */
public interface FavoriteRepository extends JpaRepository<Favorite, Long>, JpaSpecificationExecutor<Favorite> {

    /**
     * 查询
     * @param userId 用户id
     * @param postId 文章id
     * @return
     */
    Favorite findByUserIdAndPostId(long userId, long postId);

    /**
     * 查询
     * @param pageable
     * @param userId
     * @return
     */
    Page<Favorite> findAllByUserId(Pageable pageable, long userId);

    /**
     * 删除
     * @param postId 文章id
     * @return
     */
    int deleteByPostId(long postId);
}
